package com.situ.common;

import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.annotation.WebListener;

import java.io.InputStream;
import java.util.Properties;

@WebListener
public class MyListener
        implements ServletContextListener {
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("销毁");
    }

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        InputStream resourceAsStream = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("jdbc.properties");
        Properties properties = new Properties();
        try {
            properties.load(resourceAsStream);
            String jdbcUrl = properties.getProperty("JDBC_URL");
            String jdbcUser = properties.getProperty("JDBC_USER");
            String jdbcPassword = properties.getProperty("JDBC_PASSWORD");
            String jdbcDriver = properties.getProperty("JDBC_DRIVER");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
